﻿Imports System.Data.OleDb
Imports System
Public Class ExcelProvider
    Private Shared conn As OleDbConnection
    Private Shared ConnectionString
    Public Shared Function OpenConnection(ByVal path As String) As OleDbConnection
        ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties= Excel 12.0"
        conn = New OleDbConnection((ConnectionString))
        conn.Open()
        Return conn
    End Function

    Public Shared Function ExecSelect(ByVal sql As String) As DataSet
        Dim adap As New OleDbDataAdapter(sql, conn)
        Dim dt As New DataSet()
        adap.Fill(dt, "Sheet1")
        Return dt
    End Function

    Public Shared Sub CloseConnection()
        conn.Close()
    End Sub
End Class
